package com.jxtti.service;

import org.apache.log4j.Logger;

import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import com.jxtti.dao.DisciplinaryReportDao;
import com.jxtti.entity.DisciplinaryReport;

/**
 * 
 * <br>
 */
@Service("disciplinaryReportService")
@Transactional(rollbackFor = { RuntimeException.class, Exception.class })
public class DisciplinaryReportService {

	private final static Logger log = Logger.getLogger(DisciplinaryReportService.class);

	@Autowired
	private DisciplinaryReportDao disciplinaryReportDao;

	/**
	 * 获取信息数据列表--后台
	 * 
	 * @param data
	 * @return
	 */
	public PageInfo<DisciplinaryReport> list(Map<String, Object> data) {
		// 第几页
		int pageNum = Integer.parseInt(
				(data.get("page") == null || data.get("page").equals("0")) ? "1" : data.get("page").toString());
		// 每页显示条数 
		int pageSize = Integer.parseInt(
				(data.get("rows") == null || data.get("rows").equals("0")) ? "10" : data.get("rows").toString());

		PageHelper.startPage(pageNum, pageSize);
		PageInfo<DisciplinaryReport> pages = new PageInfo<DisciplinaryReport>(disciplinaryReportDao.queryByList(data));
		return pages;
	}

	public Map<String, Object> listDesk(Map<String, Object> data, DisciplinaryReport disciplinaryReport) {

		int pageNum = Integer.parseInt((data.get("currentPage") == null || data.get("currentPage").equals("0")) ? "1"
				: data.get("currentPage").toString());

		int pageSize = Integer.parseInt((data.get("pageSize") == null || data.get("pageSize").equals("0")) ? "10"
				: data.get("pageSize").toString());
		PageHelper.startPage(pageNum, pageSize);
		PageInfo<DisciplinaryReport> pages = new PageInfo<DisciplinaryReport>(disciplinaryReportDao.queryByList(data));
		data.put("page", pages);
		return data;
	}
	
	// 前台分页
	public  PageInfo<DisciplinaryReport> listPage(Map<String, Object> data){
		//第几页
		int pageNum = Integer.parseInt((data.get("currPageNum") == null || data.get("currPageNum").equals("0")) ? "1" : data.get("currPageNum").toString());
		// 每页显示条数 
		int pageSize = Integer.parseInt((data.get("pageRowSize") == null || data.get("pageRowSize").equals("0")) ? "10" : data.get("pageRowSize").toString());
		
		PageHelper.startPage(pageNum, pageSize);			
		PageInfo<DisciplinaryReport> pages = new PageInfo<DisciplinaryReport>(disciplinaryReportDao.queryForIndex(data));		
		return pages;
	}
	
	
	public List<DisciplinaryReport>  queryForIndex(Map<String, Object> data){
		return  disciplinaryReportDao.queryForIndex(data);
	}
	
	


	/**
	 * 查询所有数据。
	 * 
	 * @param data
	 * @return
	 */
	public List<DisciplinaryReport> queryAll(Map<String, Object> data) {
		return disciplinaryReportDao.queryByList(data);
	}

	/**
	 * 添加数据.
	 * 
	 * @param data
	 * @return
	 */
	public int add(DisciplinaryReport disciplinaryReport) {
		int insertCount = disciplinaryReportDao.add(disciplinaryReport);
		return insertCount;
	}

	/**
	 * 修改数据.
	 * 
	 * @param data
	 * @return
	 */
	public int update(DisciplinaryReport disciplinaryReport) {
		int updateCount = disciplinaryReportDao.update(disciplinaryReport);
		return updateCount;
	}

	/**
	 * 删除数据.
	 * 
	 * @param data
	 * @return
	 */
	public int delete(DisciplinaryReport disciplinaryReport) {
		int deleteCount = disciplinaryReportDao.delete(disciplinaryReport);
		return deleteCount;
	}

	public DisciplinaryReport queryById(DisciplinaryReport disciplinaryReport) {
		disciplinaryReport = disciplinaryReportDao.queryById(disciplinaryReport);
		return disciplinaryReport;
	}

}
